home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_3a.arc / KEYBOARD.CLS < prev    next >
Text File  |  1989-02-21  |  2KB  |  79 lines

  1. // keyboard.cls    a Keyboard class for C++.
  2. //
  3. // this file implements a Keyboard class.  it hides system details from
  4. // the class user.
  5. //
  6. // (c) Aspen Scientific 1989. All Rights Reserved.
  7. // Author: Vaughn Vernon
  8.  
  9. #ifndef __KEYBOARD_CLASS__
  10.  
  11. # define __KEYBOARD_CLASS__    1
  12.  
  13. # define extMask    0x8000
  14.  
  15. // Keyboard class
  16.  
  17. class Keyboard {
  18.  
  19. protected:
  20.     int    keyI;        // saves latest input
  21. public:
  22.     Keyboard()            { keyI = -1; }
  23.     ~Keyboard()            { }
  24.  
  25.     // methods
  26.  
  27.     int    input(int wait =1);
  28.     int    value()            { return keyI; }
  29.     int    operator==(int keyComp) { return (keyI == keyComp); }
  30.     Keyboard & operator>>(int & k)    { k = input(1); return *this; }
  31.     void    flush()            { while (input(0) != -1) ; }
  32. };
  33.  
  34.  
  35. // KeyTypes class
  36.  
  37. class KeyTypes {
  38. public:
  39.     KeyTypes()    { }
  40.     ~KeyTypes()    { }
  41.  
  42.     // these methods are used to compare input to
  43.     int    None()        { return (-1); }
  44.     int    Escape()    { return 27; }
  45.     int    SpaceBar()    { return ' '; }
  46.     int    Tab()        { return '\t'; }
  47.     int    BackTab()    { return 15; }
  48.  
  49.     int    Printable(int key)    {
  50.             return (key >= 32 && key <= 127);
  51.     }
  52.     int    ASCII(int key)    {
  53.             return (key >= 0 && key <= 255);
  54.     }
  55.     int    Ctrl(char c)    { return (c & 037); }
  56.  
  57.     int    Home()        { return (71 | extMask); }
  58.     int    End()        { return (79 | extMask); }
  59.     int    PgUp()        { return (73 | extMask); }
  60.     int    PgDn()        { return (81 | extMask); }
  61.     int    Left()        { return (75 | extMask); }
  62.     int    Right()        { return (77 | extMask); }
  63.     int    Up()        { return (72 | extMask); }
  64.     int    Down()        { return (80 | extMask); }
  65.  
  66.     int    F1()        { return (59 | extMask); }
  67.     int    F2()        { return (60 | extMask); }
  68.     int    F3()        { return (61 | extMask); }
  69.     int    F4()        { return (62 | extMask); }
  70.     int    F5()        { return (63 | extMask); }
  71.     int    F6()        { return (64 | extMask); }
  72.     int    F7()        { return (65 | extMask); }
  73.     int    F8()        { return (66 | extMask); }
  74.     int    F9()        { return (67 | extMask); }
  75.     int    F10()        { return (68 | extMask); }
  76. };
  77.  
  78. #endif // __KEYBOARD_CLASS__
  79.